package cn.lkx.eduservice.service.impl;

import cn.lkx.eduservice.entity.EduTeacher;
import cn.lkx.eduservice.entity.vo.TeacherQuery;
import cn.lkx.eduservice.mapper.EduTeacherMapper;
import cn.lkx.eduservice.service.TeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class TeacherServiceImpl extends ServiceImpl<EduTeacherMapper,EduTeacher> implements TeacherService {
    /**
     * 多条件可变查询，Mybatis动态SQL实现，mp 可以用以下实现
     * @param pageParam
     * @param teacherQuery
     */
    @Override
    public void pageQueryConditions(Page<EduTeacher> pageParam, TeacherQuery teacherQuery) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        String name = teacherQuery.getName();
        Integer level = teacherQuery.getLevel();
        String begin = teacherQuery.getBegin();
        String end = teacherQuery.getEnd();
        if( !StringUtils.isEmpty(name)){  //条件不为空，加入wrapper
            queryWrapper.like("name",name);
        }
        if ( !StringUtils.isEmpty(level)){
            queryWrapper.eq("level",level); //数据库的字段名,不是属性名
        }
        if ( !StringUtils.isEmpty(begin)){
            queryWrapper.ge("gmt_create",begin);
        }
        if ( !StringUtils.isEmpty(end)){
            queryWrapper.le("gmt_modified",end);
        }
        queryWrapper.orderByDesc("gmt_create");
        baseMapper.selectPage(pageParam,queryWrapper);

    }
}
